home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / pyxmpp / sasl / plain.pyo (.txt) < prev   
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __revision__ = '$Id: plain.py 647 2006-08-26 18:27:39Z jajcus $'
  5. __docformat__ = 'restructuredtext en'
  6. import logging
  7. from pyxmpp.utils import to_utf8, from_utf8
  8. from pyxmpp.sasl.core import ClientAuthenticator, ServerAuthenticator
  9. from pyxmpp.sasl.core import Success, Failure, Challenge, Response
  10.  
  11. class PlainClientAuthenticator(ClientAuthenticator):
  12.     
  13.     def __init__(self, password_manager):
  14.         ClientAuthenticator.__init__(self, password_manager)
  15.         self.username = None
  16.         self.finished = None
  17.         self.password = None
  18.         self.authzid = None
  19.         self._PlainClientAuthenticator__logger = logging.getLogger('pyxmpp.sasl.PlainClientAuthenticator')
  20.  
  21.     
  22.     def start(self, username, authzid):
  23.         self.username = username
  24.         if authzid:
  25.             self.authzid = authzid
  26.         else:
  27.             self.authzid = ''
  28.         self.finished = 0
  29.         return self.challenge('')
  30.  
  31.     
  32.     def challenge(self, challenge):
  33.         _unused = challenge
  34.         if self.finished:
  35.             self._PlainClientAuthenticator__logger.debug('Already authenticated')
  36.             return Failure('extra-challenge')
  37.         
  38.         self.finished = 1
  39.         if self.password is None:
  40.             (self.password, pformat) = self.password_manager.get_password(self.username)
  41.         
  42.         if not (self.password) or pformat != 'plain':
  43.             self._PlainClientAuthenticator__logger.debug("Couldn't retrieve plain password")
  44.             return Failure('password-unavailable')
  45.         
  46.         return Response('%s\x00%s\x00%s' % (to_utf8(self.authzid), to_utf8(self.username), to_utf8(self.password)))
  47.  
  48.     
  49.     def finish(self, data):
  50.         _unused = data
  51.         return Success(self.username, None, self.authzid)
  52.  
  53.  
  54.  
  55. class PlainServerAuthenticator(ServerAuthenticator):
  56.     
  57.     def __init__(self, password_manager):
  58.         ServerAuthenticator.__init__(self, password_manager)
  59.         self._PlainServerAuthenticator__logger = logging.getLogger('pyxmpp.sasl.PlainServerAuthenticator')
  60.  
  61.     
  62.     def start(self, response):
  63.         if not response:
  64.             return Challenge('')
  65.         
  66.         return self.response(response)
  67.  
  68.     
  69.     def response(self, response):
  70.         s = response.split('\x00')
  71.         if len(s) != 3:
  72.             self._PlainServerAuthenticator__logger.debug('Bad response: %r' % (response,))
  73.             return Failure('not-authorized')
  74.         
  75.         (authzid, username, password) = s
  76.         authzid = from_utf8(authzid)
  77.         username = from_utf8(username)
  78.         password = from_utf8(password)
  79.         if not self.password_manager.check_password(username, password):
  80.             self._PlainServerAuthenticator__logger.debug('Bad password. Response was: %r' % (response,))
  81.             return Failure('not-authorized')
  82.         
  83.         info = {
  84.             'mechanism': 'PLAIN',
  85.             'username': username }
  86.         if self.password_manager.check_authzid(authzid, info):
  87.             return Success(username, None, authzid)
  88.         else:
  89.             self._PlainServerAuthenticator__logger.debug('Authzid verification failed.')
  90.             return Failure('invalid-authzid')
  91.  
  92.  
  93.